package com.yt.entity;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @Classname Test
 * @Description
 * @Date 2021/11/10 8:20
 * @Create by 杨涛
 */
public class Test {
    public static void main(String[] args) {
        Map<String,String> req=new HashMap<>() ;
        req.put("uid","1");
        req.put("username","admin");
        req.put("password","admin");

        User user=new User();
       Class userClass=user.getClass();
       Field [] fs =userClass.getDeclaredFields();
        for(Field f:fs){
//            System.out.println(f.getName());
           Object value = req.get(f.getName());
           if (f.getName().equals("uid")){
               try{
                   f.set(user,Integer.parseInt(value.toString()));
               }  catch (IllegalAccessException e) {
                   e.printStackTrace();
               }
           }else{
               try{
                   f.set(user,value);
               }  catch (IllegalAccessException e) {
                   e.printStackTrace();
               }
           }


        }
        System.out.println(user);
    }
}
